<?php


abstract class BaseGenericObject extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	public $id;


	
	public $objectid;


	
	public $object_type;


	
	public $parent;


	
	public $is_histo;


	
	public $deleted;


	
	public $order_rank;


	
	public $deleted_at;


	
	public $created_at;

	
	protected $aUniqueId;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getObjectid()
	{

		return $this->objectid;
	}

	
	public function getObjectType()
	{

		return $this->object_type;
	}

	
	public function getParent()
	{

		return $this->parent;
	}

	
	public function getIsHisto()
	{

		return $this->is_histo;
	}

	
	public function getDeleted()
	{

		return $this->deleted;
	}

	
	public function getOrderRank()
	{

		return $this->order_rank;
	}

	
	public function getDeletedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->deleted_at === null || $this->deleted_at === '') {
			return null;
		} elseif (!is_int($this->deleted_at)) {
						$ts = strtotime($this->deleted_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [deleted_at] as date/time value: " . var_export($this->deleted_at, true));
			}
		} else {
			$ts = $this->deleted_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getCreatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->created_at === null || $this->created_at === '') {
			return null;
		} elseif (!is_int($this->created_at)) {
						$ts = strtotime($this->created_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [created_at] as date/time value: " . var_export($this->created_at, true));
			}
		} else {
			$ts = $this->created_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = GenericObjectPeer::ID;
		}

	} 
	
	public function setObjectid($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->objectid !== $v) {
			$this->objectid = $v;
			$this->modifiedColumns[] = GenericObjectPeer::OBJECTID;
		}

		if ($this->aUniqueId !== null && $this->aUniqueId->getId() !== $v) {
			$this->aUniqueId = null;
		}

	} 
	
	public function setObjectType($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->object_type !== $v) {
			$this->object_type = $v;
			$this->modifiedColumns[] = GenericObjectPeer::OBJECT_TYPE;
		}

	} 
	
	public function setParent($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->parent !== $v) {
			$this->parent = $v;
			$this->modifiedColumns[] = GenericObjectPeer::PARENT;
		}

	} 
	
	public function setIsHisto($v)
	{

		if ($this->is_histo !== $v) {
			$this->is_histo = $v;
			$this->modifiedColumns[] = GenericObjectPeer::IS_HISTO;
		}

	} 
	
	public function setDeleted($v)
	{

		if ($this->deleted !== $v) {
			$this->deleted = $v;
			$this->modifiedColumns[] = GenericObjectPeer::DELETED;
		}

	} 
	
	public function setOrderRank($v)
	{
		
						if ($v !== null && !is_float($v) && is_numeric($v)) {
			$v = (float) $v;
		}

		if ($this->order_rank !== $v) {
			$this->order_rank = $v;
			$this->modifiedColumns[] = GenericObjectPeer::ORDER_RANK;
		}

	} 
	
	public function setDeletedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [deleted_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->deleted_at !== $ts) {
			$this->deleted_at = $ts;
			$this->modifiedColumns[] = GenericObjectPeer::DELETED_AT;
		}

	} 
	
	public function setCreatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [created_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->created_at !== $ts) {
			$this->created_at = $ts;
			$this->modifiedColumns[] = GenericObjectPeer::CREATED_AT;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->objectid = $rs->getInt($startcol + 1);

			$this->object_type = $rs->getString($startcol + 2);

			$this->parent = $rs->getString($startcol + 3);

			$this->is_histo = $rs->getBoolean($startcol + 4);

			$this->deleted = $rs->getBoolean($startcol + 5);

			$this->order_rank = $rs->getFloat($startcol + 6);

			$this->deleted_at = $rs->getTimestamp($startcol + 7, null);

			$this->created_at = $rs->getTimestamp($startcol + 8, null);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 9; 
		} catch (Exception $e) {
			throw new PropelException("Error populating GenericObject object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(GenericObjectPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			GenericObjectPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
    if ($this->isNew() && !$this->isColumnModified(GenericObjectPeer::CREATED_AT))
    {
      $this->setCreatedAt(time());
    }

		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(GenericObjectPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->aUniqueId !== null) {
				if ($this->aUniqueId->isModified()) {
					$affectedRows += $this->aUniqueId->save($con);
				}
				$this->setUniqueId($this->aUniqueId);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = GenericObjectPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += GenericObjectPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aUniqueId !== null) {
				if (!$this->aUniqueId->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aUniqueId->getValidationFailures());
				}
			}


			if (($retval = GenericObjectPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = GenericObjectPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getObjectid();
				break;
			case 2:
				return $this->getObjectType();
				break;
			case 3:
				return $this->getParent();
				break;
			case 4:
				return $this->getIsHisto();
				break;
			case 5:
				return $this->getDeleted();
				break;
			case 6:
				return $this->getOrderRank();
				break;
			case 7:
				return $this->getDeletedAt();
				break;
			case 8:
				return $this->getCreatedAt();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = GenericObjectPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getObjectid(),
			$keys[2] => $this->getObjectType(),
			$keys[3] => $this->getParent(),
			$keys[4] => $this->getIsHisto(),
			$keys[5] => $this->getDeleted(),
			$keys[6] => $this->getOrderRank(),
			$keys[7] => $this->getDeletedAt(),
			$keys[8] => $this->getCreatedAt(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = GenericObjectPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setObjectid($value);
				break;
			case 2:
				$this->setObjectType($value);
				break;
			case 3:
				$this->setParent($value);
				break;
			case 4:
				$this->setIsHisto($value);
				break;
			case 5:
				$this->setDeleted($value);
				break;
			case 6:
				$this->setOrderRank($value);
				break;
			case 7:
				$this->setDeletedAt($value);
				break;
			case 8:
				$this->setCreatedAt($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = GenericObjectPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setObjectid($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setObjectType($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setParent($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setIsHisto($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setDeleted($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setOrderRank($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setDeletedAt($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setCreatedAt($arr[$keys[8]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(GenericObjectPeer::DATABASE_NAME);

		if ($this->isColumnModified(GenericObjectPeer::ID)) $criteria->add(GenericObjectPeer::ID, $this->id);
		if ($this->isColumnModified(GenericObjectPeer::OBJECTID)) $criteria->add(GenericObjectPeer::OBJECTID, $this->objectid);
		if ($this->isColumnModified(GenericObjectPeer::OBJECT_TYPE)) $criteria->add(GenericObjectPeer::OBJECT_TYPE, $this->object_type);
		if ($this->isColumnModified(GenericObjectPeer::PARENT)) $criteria->add(GenericObjectPeer::PARENT, $this->parent);
		if ($this->isColumnModified(GenericObjectPeer::IS_HISTO)) $criteria->add(GenericObjectPeer::IS_HISTO, $this->is_histo);
		if ($this->isColumnModified(GenericObjectPeer::DELETED)) $criteria->add(GenericObjectPeer::DELETED, $this->deleted);
		if ($this->isColumnModified(GenericObjectPeer::ORDER_RANK)) $criteria->add(GenericObjectPeer::ORDER_RANK, $this->order_rank);
		if ($this->isColumnModified(GenericObjectPeer::DELETED_AT)) $criteria->add(GenericObjectPeer::DELETED_AT, $this->deleted_at);
		if ($this->isColumnModified(GenericObjectPeer::CREATED_AT)) $criteria->add(GenericObjectPeer::CREATED_AT, $this->created_at);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(GenericObjectPeer::DATABASE_NAME);

		$criteria->add(GenericObjectPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setObjectid($this->objectid);

		$copyObj->setObjectType($this->object_type);

		$copyObj->setParent($this->parent);

		$copyObj->setIsHisto($this->is_histo);

		$copyObj->setDeleted($this->deleted);

		$copyObj->setOrderRank($this->order_rank);

		$copyObj->setDeletedAt($this->deleted_at);

		$copyObj->setCreatedAt($this->created_at);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new GenericObjectPeer();
		}
		return self::$peer;
	}

	
	public function setUniqueId($v)
	{


		if ($v === null) {
			$this->setObjectid(NULL);
		} else {
			$this->setObjectid($v->getId());
		}


		$this->aUniqueId = $v;
	}


	
	public function getUniqueId($con = null)
	{
				include_once 'lib/model/om/BaseUniqueIdPeer.php';

		if ($this->aUniqueId === null && ($this->objectid !== null)) {

			$this->aUniqueId = UniqueIdPeer::retrieveByPK($this->objectid, $con);

			
		}
		return $this->aUniqueId;
	}

} 